1. Technical Field
The present invention relates to an improved data processing system. In particular, the present invention relates to Java native functions in a data processing system. Still more particular, the present invention relates to inlining Java native function calls in compiled Java code in a data processing system.
2. Description of Related Art
Java is an object oriented programming language and environment focusing on defining data as objects and the methods that may be applied to those objects. Java supports only single inheritance, meaning that each class can inherit from only one other class at any given time. Java also allows for the creation of totally abstract classes known as interfaces, which allow the defining of methods that may be shared with several classes without regard for how other classes are handling the methods. Java provides a mechanism to distribute software and extends the capabilities of a Web browser because programmers can write an applet once and the applet can be run on any Java enabled machine on the Web.
The Java virtual machine (JVM) is a virtual computer component that resides only in memory. The JVM allows Java programs to be executed on different platforms as opposed to only the one platform for which the code was compiled. Java programs are compiled for the JVM. In this manner Java is able to support applications for many types of data processing systems, which may contain a variety of central processing units and operating systems architectures. To enable a Java application to execute on different types of data processing systems, a compiler typically generates an architecture-neutral file format—the compiled code is executable on many processors, given the presence of the Java run time system. The Java compiler generates Bytecode instructions that are non-specific to particular computer architectures. A Bytecode is a machine independent code generated by the Java compiler and interpreted by a Java interpreter. A Java interpreter is a module in the JVM that alternatively decodes and executes a Bytecode or Bytecodes. These Bytecode instructions are designed to be easy to interpret on any machine and easily translated on the fly into native machine code.
A development environment, such as the Java Development Kit (JDK) available from Sun Microsystems, Inc., may be used to build Java Bytecode from Java language source code and libraries. This Java Bytecode may be stored as a Java application or applet on a Web Server, where it can be downloaded over a network to a user's machine and executed on a local JVM.
The Java run-time environment is specifically designed to limit the harm that a Java application can cause to the system that it is running on. This is especially important with the World Wide Web, where Java applets are downloaded and executed automatically when a user visits a Web page that contains Java applets. Normally one would not want to execute random programs; they might contain viruses, or they might even be potentially malicious themselves and not merely carrying unwelcome code unintentionally. Unless the user specifically allows it (by setting the appropriate flags in the user-interface to the JVM), a Java applet cannot read or write to attached storage devices (except perhaps to a specific, restricted area), nor can it read or write to memory locations (except to a specific, restricted area).
Not only are Java applets designed for downloading over the network, standard Java libraries also specifically support client-server computing. The Java language includes provisions for multi-threading and for network communications. Compared to other languages (such as C), it is much easier to write a pair of programs, one executing locally on the user's computer that is handling the user-interaction, and the other executing remotely on a server, which is performing potentially more sophisticated and processor-intensive work.
While the Java language is designed to be platform-independent, and to execute primarily in a secure environment, programmers can extend Java applications through the use of compiled native binary code on the host operating system using C-style calling conventions through the Java Native Interface (JNI). In this fashion, a Java application can have complete access to the host operating system, including reading and writing to attached I/O devices, memory, etc. Because of this, Java programs can accomplish tasks that are not normally allowed via the JVM at the cost of being platform-specific. However, with a well-designed architecture, a Java language programmer can cleanly isolate the platform-independent portion, and present a clean, platform-independent object API to other Java components while at the same time accomplishing platform-specific tasks.
When invoking native function calls in the compiled Java code through the JNI, overheads are associated. For example, work must be performed at run time in order to prepare the call for invocation. Generally, a native library containing the native function must be loaded on or before being called. The native function must also be resolved in the runtime system, and related JVM data structures must be updated to indicate the use of the native function.
In addition, the JVM must also set up native stacks and/or registers according to the functional calling convention of the underlying operating system architecture and perform null-checking on reference arguments. For some JVMs, set up is also needed to add information for garbage collection. Upon returning from the native code, the used stack and/or registers must be restored after the return value from the native code is returned to the Java runtime environment.
Several attempts have been made to minimize the overhead of invoking native functions. The first of which are programmer-based optimizations that put the onus on the application programmer to practice efficient coding techniques when writing Java code that uses native functions. For example, batching native calls and passing as much data as possible to native code per function call, such that boundary crossing in Java programs may be reduced.
Another attempt to minimize the overhead involves restricting the type of functionality offered in the native code. For example, mechanisms which bypass construction of special wrapper code that would otherwise be found preceding native call frames on the call stack. However, such mechanisms can only be used for methods that are guaranteed not to require stack-walking support, including garbage collection, exception handling, synchronization or security, since these are services that the wrapper code helps to provide.
In yet another attempt to minimize overhead, work is performed to introduce unmanaged memory into the JVM by mapping Bytecodes to low-level assembly statements. With high speed access to unmanaged memory, shared memory segments, memory mapped files, communication and I/O buffers and memory mapped hardware devices may be implemented. However, this attempt does not recognize and map long complex sequences of Bytecodes, or apply mappings to virtual method invocations, since code mappings cannot handle dynamic class loading.
While the above attempts minimize some overhead of native function calls, each of the attempts has its own drawback. Therefore, it would be advantageous to have an improved method, apparatus, and computer instructions that target optimization of native function calls, in order to minimize the overhead.